<style>
    .g_p_type{
        display: none;
    }
    .fo{
        color:red;
    }
</style>

<a href="/admin/product/index" class="btn btn-danger btn-del btn-disabled" title="返回产品列表"> 返回产品列表</a>
<div class="content">
    <div id="add-form" class="form-horizontal nice-validator n-default n-bootstrap" role="form" data-toggle="validator" novalidate="novalidate">
        <?php for($i=0;$i<$count;$i++){ ?>
            <div class="form-group {if condition='$list[$i]["p_id"]==$pid'}fo{/if}">
                <label class="control-label col-xs-12 col-sm-2" >
                  <!--  ID:<?php echo $list[$i]['id'];?>
                    title:<?php echo $list[$i]['title'];?>
                    上一个:<?php if($i>0){echo $list[$i-1]['id']; }?>
                    下一个:<?php if($i<$count-1){echo $list[$i+1]['id'];}?>-->
                    <?php echo $list[$i]['pro_name']['s_name']; ?>----<?php echo $list[$i]['p_id']; ?>
                </label>
                <div class="col-xs-12 col-sm-8" style="width:200px;">
                    <input class="form-control"  nomain="maintext" info="<?php echo $list[$i]['id'];?>" name="<?php echo $list[$i]['id'];?>" value=" <?php echo $list[$i]['title'];?>" type="text">
                </div>
                <label class="control-label col-xs-12 col-sm-2" style="text-align: left;">
                    <span><?php echo AB_line($list[$i]['l_order']);?>线路</span>
                    <?php if($i>0){?>
                    <button  class="subUp" name="<?php echo $list[$i]['id'];?>"  data_up="<?php if($i>0){echo $list[$i-1]['id']; }?>">向上</button>
                    <?php }?>
                    <?php if($i<($count-1)){?>
                    <button  class="subDown" data_down="<?php if($i<$count-1){echo $list[$i+1]['id'];}?>" name="<?php echo $list[$i]['id'];?>" >向下</button>
                    <?php }?>
                </label>
            </div>
        <?php }?>
            <div class="form-group layer-footer">
                <label class="control-label col-xs-12 col-sm-2"></label>
                <div class="col-xs-12 col-sm-8" >
                    <button type="button" class="btn btn-success btn-embossed" onclick="splitSub();">拆分</button>
                    <button type="button" class="btn btn-success btn-embossed" onclick="editSub()">确认修改</button>
                </div>
            </div>


    </form>

</div>
<form id="maintext" method="post">

</form>
<div class="content">
    <form id="add-form1" class="form-horizontal nice-validator n-default n-bootstrap" role="form" data-toggle="validator" method="POST" action="" novalidate="novalidate">

        {volist name="other" id="other"}
            {volist name="$other['other']" id="v1"}
                <div class="form-group">
                    <label class="control-label col-xs-12 col-sm-2">{$v1['pro_name']['s_name']}--{$v1.p_id}:</label>
                    <div class="col-xs-12 col-sm-8" style="width:200px;">
                        <input  class="form-control" value="{$v1.title}" name="title" type="text" readonly="readonly">
                    </div>
                    <label class="control-label col-xs-12 col-sm-2" style="text-align: left;">
                        <span>{$v1.l_order|AB_line=###}线路</span>
                    </label>
                </div>
            {/volist}
        <div class="form-group layer-footer">
            <label class="control-label col-xs-12 col-sm-2"></label>
            <div class="col-xs-12 col-sm-8">
                <button type="button" class="btn btn-success btn-embossed" onclick="addSub({$other['linkno']});">添加</button>
            </div>
        </div>
        {/volist}



    </form>
</div>
<script language="javascript" type="text/javascript" src="/assets/My97DatePicker/jquery-1.8.2.js"></script>
<script>
function addSub(no){
    var pid="{$pid}";
    $.ajax({
        type:'post',
        dataType:'json',
        url:"/admin/product/product_line_add",
        data:{"pid":pid,"linkno":no},
        success:function(data){
                if(data==1){
                    window.location.href="/admin/product/product_line?id="+pid;
                }else{
                    alert("数据修改失败");
                }
        }
    })
}

function splitSub(){
    var pid="{$pid}";
    $.ajax({
        type:'post',
        dataType:'json',
        url:"/admin/product/product_line_split",
        data:{"pid":pid},
        success:function(data){
            if(data==1){
                window.location.href="/admin/product/product_line?id="+pid;
            }else{
                alert("数据拆分失败");
            }
        }
    })
}

function editSub(){
    var inputarr=  $("input[nomain='maintext']");
    var inputstr="";

    for(var i=0;i<inputarr.length;i++){
        var obj1=$(inputarr[i]);
        var input1="<input name='"+obj1.attr("info")+"' value='"+obj1.val()+"' type='hidden'/>";
        inputstr=inputstr+input1;
    }

    $("#maintext").html(inputstr);

    $("#maintext").submit();

}

</script>

<script>
    $(".subUp").click(function(){
        var id=$(this).attr("name");
        var prev_id=$(this).attr("data_up");
        var pid="{$pid}";
        $.ajax({
            type:'post',
            dataType:'json',
            url:'/admin/product/product_line_up',
            data:{"id":id,"prev_id":prev_id},
            success:function(data){
                if(data==1){
                    window.location.href="/admin/product/product_line?id="+pid;
                }else{
                    alert("数据更改失败");
                }

            }

        })

    })

    $(".subDown").click(function(){
        var pid="{$pid}";
        var id=$(this).attr("name");
        var next_id=$(this).attr("data_down");
       // alert(next_id);
        $.ajax({
            type:'post',
            dataType:'json',
            url:'/admin/product/product_line_down',
            data:{"id":id,"next_id":next_id},
            success:function(data){
                if(data==1){
                    window.location.href="/admin/product/product_line?id="+pid;
                }else{
                    alert("数据更改失败");
                }

            }

        })

    })
</script>




